package club.kingyin.kyblog.core.business.service.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.Instant;

/**
 * @author ：kingyin
 * @date ：创建于 2021/8/26 12:02 下午
 * @description ：
 * @modified By：
 * @version: 1.0.0
 */
@Service
public class AuthorityService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public void publish(String token) {
        // token默认保存24小时
        redisTemplate.opsForValue().set(token,"1", Duration.ofMillis(24 * 60 * 60 * 1000));
    }

    public boolean verify(String token) {
        try {
            if ("1".equals(redisTemplate.opsForValue().get(token)))
                return true;
        } catch (Exception e) {
            return false;
        }
        return false;
    }

    public boolean repeal(String token) {
        try {
            return redisTemplate.delete(token);
        } catch (Exception e) {
            return false;
        }

    }
}
